import datetime

# 获取当前时间
now = datetime.datetime.now()
receipt_id = f"DH{now.strftime('%Y%m%d')}0002"
time_str = now.strftime("%Y-%m-%d %H:%M:%S")

# 商品信息（更新为指定商品和数量）
products = [
    {"name": "薯片", "quantity": 10, "price": 4.50},
    {"name": "泡面", "quantity": 10, "price": 3.80},
    {"name": "辣条", "quantity": 18, "price": 2.50},
    {"name": "糖果", "quantity": 18, "price": 1.80},
    {"name": "鸡腿", "quantity": 18, "price": 6.50}
]

# 计算总数和总额
total_quantity = sum(item["quantity"] for item in products)
total_amount = sum(item["quantity"] * item["price"] for item in products)

# 打印小票
print("=" * 45)
print("便民超市购物凭证".center(45))
print(f"单号：{receipt_id}".ljust(45))
print(f"时间：{time_str}".ljust(45))
print("-" * 45)
# 标题列使用固定宽度确保对齐
print("{:<12} | {:>6} | {:>8} | {:>10}".format("商品名称", "数量", "单价(元)", "金额(元)"))
print("-" * 45)

for item in products:
    amount = item["quantity"] * item["price"]
    # 数字右对齐，确保垂直方向对齐
    print("{:<12} | {:>6d} | {:>8.2f} | {:>10.2f}".format(
        item["name"], 
        item["quantity"], 
        item["price"], 
        amount
    ))

print("-" * 45)
# 总计信息右对齐
print(f"{'总数：':<32}{total_quantity:>12d}")
print(f"{'总额：':<32}{total_amount:>12.2f}")
print(f"{'折后总额：':<32}{total_amount:>12.2f}")
print(f"{'实收：':<32}{total_amount:>12.2f}")
print(f"{'找零：':<32}{0.00:>12.2f}")
print("-" * 45)
print("收银员：007".ljust(45))
print("感谢惠顾，欢迎下次光临！".center(45))
print("=" * 45)
    